﻿using System;
using System.Windows.Automation;

namespace RobotUI.Controls
{
	/// <summary>
	/// Converts AutomationElement to specific control
	/// </summary>
	public class ElementAdapter
	{
		
		public static Control Adapt(AutomationElement element)
		{
			//get type
			if (element==null) throw new ArgumentNullException("Cannot adapt null element");
			var contype = element.Current.ControlType;
			
			//convert
			
			//button
			if (contype.Equals(ControlType.Button))
			{
				return new Button(element);
			}
			
			//edit
			if (contype.Equals(ControlType.Edit))
			{
				return new Edit(element);
			}
			
			//text
			if (contype.Equals(ControlType.Text))
			{
				return new Text(element);
			}
			
			
			//couldnt adapt it
			throw new Exception("Unable to adapt element to control type");
			
		}
		

	}
}
